package com.zombie.effect;


import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector2;
import com.zombie.Constants;
import com.zombie.ResourceManager;
import com.zombie.state.GameState;

public class TextEffect extends AbstractEffect{

	public String text ="Text Text Text Text Text Text Text Text Text Text ";
	String shownText = "";
	public long allTextShownTime = 8000L;
	public int symbolShowTime = 50;
	public Color color = Color.RED;
	public boolean soundOn = false;
	
	public TextEffect(){
		setFullLifeTime(8000);
		position = new Vector2(50,500);
		renderGroup = Constants.GROUP_LAST;
	}
	
	@Override
	public void update(int delta) {
		setLifeTime(getLifeTime()-delta);
		if (getFullLifeTime()-getLifeTime() < symbolShowTime*text.length()){
//			System.out.println("Elapsed: " + (getFullLifeTime()-getLifeTime()) + " ; shown symbols: " + shownText.length() + " ; timeFor1Symbol "+ timeToShowChar + " ; shownText: " + shownText);
			if (shownText.length()*symbolShowTime + symbolShowTime < getFullLifeTime()-getLifeTime())
				if (text.length() >= shownText.length()+ 1){
					shownText+=text.substring(shownText.length(),shownText.length()+ 1);
					if (soundOn)
						ResourceManager.getSound("click").play();
				}
		}
		if (getLifeTime() < 500){
			if (shownText.length()>1)
				shownText = shownText.substring(0, shownText.length()-1);
		}
	}

	@Override
	public void remove() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void draw(SpriteBatch batch, ShapeRenderer shapeBatch) {
		GameState.getInstance().font.drawMultiLine(batch, shownText, position.x, position.y);
	}


}
